<?php
// +----------------------------------------------------------------------
// | Trackback
// +----------------------------------------------------------------------
// | @link ( http://www.yurnero.net )
// +----------------------------------------------------------------------
// | @copyright
// +----------------------------------------------------------------------
// | @licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | @author Haijun Wu <nicholasinlove@126.com>
// +----------------------------------------------------------------------
// | $Id: TrackbackAction.class.php 56 2011-03-17 15:46:38Z nicholasinlove1986@gmail.com $
// +----------------------------------------------------------------------


class TrackbackAction extends BaseAction {

    //发送记录
	public function sendTrackbackLog() {
		//排序字段 默认为主键
		if (isset($_REQUEST ['order'])) {
			$order = $_REQUEST ['order'];
		} else {
			$order = 'tbl_id';
		}
		//排序方式 默认按照倒序排列
		if (isset($_REQUEST ['sort'])) {
			$sort = $_REQUEST ['sort'];
		} else {
			$sort = 'desc';
		}	
								
		$tbl  =  M('TrackbackLog');	
		import("@.ORG.Page");
		C ( 'PAGE_ROLLPAGE',C('page_roll') );	
		$count = $tbl->count();
		$p = new Page ($count, C('admin_list_num'));		
		$list = $tbl->field(C('DB_PREFIX').'posts.posts_title,'.C('DB_PREFIX').'posts.posts_url,'.C('DB_PREFIX').'trackback_log.*')->join(C('DB_PREFIX').'posts ON '.C('DB_PREFIX').'posts.posts_id = '.C('DB_PREFIX').'trackback_log.posts_id')->order("`".$order."` ".$sort)->limit($p->firstRow.','.$p->listRows)->findAll();
		$p->setConfig('theme',C('admin_page_theme'));
		//分页跳转的时候保证查询条件
		foreach ($map as $key => $val) {
			if (!is_array ($val)) {
				$p->parameter .= "$key=" . urlencode ( $val ) . "&";
			}
		}
		$page = $p->show ();

		$this->assign('ur_here','发送记录');
		$this->assign('pagestyle',C('admin_page_style'));
		$this->assign('page', $page);
		$this->assign('list',$list);
		$this->assign('sort',$sort);
		$this->display();
	}

    //引用管理列表
	public function listTrackback() {
		//排序字段 默认为主键
		if (isset($_REQUEST ['order'])) {
			$order = $_REQUEST ['order'];
		} else {
			$order = 'tb_id';
		}
		//排序方式 默认按照倒序排列
		if (isset($_REQUEST ['sort'])) {
			$sort = $_REQUEST ['sort'];
		} else {
			$sort = 'desc';
		}	
		//查询过滤
		$map  =	 array();
		
		if ($_REQUEST['id']!='') {
			$map[C('DB_PREFIX').'trackback.posts_id'] = $_REQUEST['id'];
		}
								
		$tbl  =  M('Trackback');	
		import("@.ORG.Page");
		C ( 'PAGE_ROLLPAGE',C('page_roll') );	
		$count = $tbl->where($map)->count();
		$p = new Page ($count, C('admin_list_num'));		
		$list = $tbl->where($map)->field(C('DB_PREFIX').'posts.posts_title,'.C('DB_PREFIX').'posts.posts_url,'.C('DB_PREFIX').'trackback.*')->join(C('DB_PREFIX').'posts ON '.C('DB_PREFIX').'posts.posts_id = '.C('DB_PREFIX').'trackback.posts_id')->order("`".$order."` ".$sort)->limit($p->firstRow.','.$p->listRows)->findAll();
		$p->setConfig('theme',C('admin_page_theme'));
		//分页跳转的时候保证查询条件
		foreach ($map as $key => $val) {
			if (!is_array ($val)) {
				$p->parameter .= "$key=" . urlencode ( $val ) . "&";
			}
		}
		$page = $p->show ();

		$this->assign('ur_here','引用列表');
		$this->assign('pagestyle',C('admin_page_style'));
		$this->assign('page', $page);
		$this->assign('list',$list);
		$this->assign('sort',$sort);
		$this->display();
	}
	
	//删除发送记录
	public function dropTrackbackLog() {
		$this->checkLimits();
		$tbl = M('TrackbackLog');
		if ($_POST['act'] == 'drop') {
			$pk   =  $tbl->getPk();
			$condition = array ($pk => array ('in', $_POST['key']));
			$list = $tbl->where($condition)->delete();
			if ($list!==false) {
				set_log('drop(TrackbackLog, Count: '.count($_POST['key']).')');
				$this->assign('jumpUrl',__URL__.'/sendTrackbackLog/');
				$this->success ('成功删除了 '.count($_POST['key']).' 个发送记录' );
			} else {
				$this->error ('操作失败');
			}
		} else {
			$this->error('非法操作');
		}
	}
	
	//删除发送记录
	public function dropTrackback() {
		$this->checkLimits();
		$tb  =  M('Trackback');
		if ($_POST['act'] == 'visible') {
			$pk   =  $tb->getPk();
			$condition = array ($pk => array ('in', $_POST['key']));
			$list = $tb->where($condition)->setField('tb_visible', 1);
			if ($list!==false) {
				set_log('edit(Trackback, Toggle, Visible, Count: '.count($_POST['key']).')');
				$this->assign('jumpUrl',__URL__.'/listTrackback/');
				$this->success ('成功显示了 '.count($_POST['key']).' 个引用通告' );
			} else {
				$this->error ('操作失败');
			}
		}
		if ($_POST['act'] == 'unvisible') {
			$pk   =  $tb->getPk();
			$condition = array ($pk => array ('in', $_POST['key']));
			$list = $tb->where($condition)->setField('tb_visible', 0);
			if ($list!==false) {
				set_log('edit(Trackback, Toggle, Visible, Count: '.count($_POST['key']).')');
				$this->assign('jumpUrl',__URL__.'/listTrackback/');
				$this->success ('成功显示了 '.count($_POST['key']).' 个引用通告' );
			} else {
				$this->error ('操作失败');
			}
		}
		if ($_POST['act'] == 'drop') {
			$pk   =  $tb->getPk();
			$condition = array ($pk => array ('in', $_POST['key']));
			$list = $tb->where($condition)->delete();
			if ($list!==false) {
				set_log('drop(Trackback, Count: '.count($_POST['key']).')');
				$this->assign('jumpUrl',__URL__.'/listTrackback/');
				$this->success ('成功删除了 '.count($_POST['key']).' 个引用通告' );
			} else {
				$this->error ('操作失败');
			}
		}					
	}
	
}

?>